package com.luoxiang.socialandroid.adapter

import android.view.View
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.luck.picture.lib.entity.LocalMedia
import com.luoxiang.socialandroid.R
import com.luoxiang.socialandroid.activity.OperationsActivity
import com.luoxiang.socialandroid.app.MyAppliaction
import com.netease.yunxin.kit.qchatkit.ui.server.viewholder.QChatServerMemberViewHolder

class SelectorphotoAdapter(data: MutableList<LocalMedia>) :
    BaseQuickAdapter<LocalMedia, BaseViewHolder>(R.layout.item_photo, data) {
    private var onItemAddClick: ((Int, String) -> Unit)? = null
    private var onItemDeleteClick: (() -> Unit)? = null
    override fun convert(holder: BaseViewHolder, item: LocalMedia) {
        val cutPath = item.cutPath
        Glide.with(MyAppliaction.getContext())
            .load(cutPath)
            .into(holder.getView(R.id.img_photo))
        holder.getView<View>(R.id.img_photo)
            .setOnClickListener { onItemAddClick?.invoke(getItemPosition(item), cutPath) }
        holder.getView<View>(R.id.icon_clearthis).setOnClickListener { v: View ->
            data.remove(item)
            onItemDeleteClick?.invoke()
            if (data.isEmpty()) {
                (v.context as OperationsActivity).setOperations(OperationsActivity.Operations.ALL)
            }

            notifyDataSetChanged()
        }
    }

    fun setOnItemAddClickListener(onItemAddClick: (Int, String) -> Unit) {
        this.onItemAddClick = onItemAddClick
    }

    fun setOnDeleteClickListener(onDeleteListener: () -> Unit) {
        this.onItemDeleteClick = onDeleteListener
    }
}